package com.sgb.kjwl.view.ui.quickentry;

import android.content.Context;
import android.view.View;

import com.swgk.core.R;
import com.swgk.core.databinding.QuickEntryPopwindowBinding;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;

/**
 * 快捷界面入口
 * LiWei  2021/10/25
 */
public class QuickEntryPopWindow extends BasePopWindow implements View.OnClickListener {

    private QuickEntryPopwindowBinding binding;
    private QuickEntryClickListener listener;

    public QuickEntryPopWindow(Context context) {
        super(context, DIR_LEFT);
    }

    @Override
    protected int popLayout() {
        return R.layout.quick_entry_popwindow;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        binding = (QuickEntryPopwindowBinding) holder.getmBinding();

        binding.btnIvHome.setOnClickListener(this::onClick);
        binding.btnIvCommodity.setOnClickListener(this::onClick);
        binding.btnIvBidding.setOnClickListener(this::onClick);
        binding.btnIvCollect.setOnClickListener(this::onClick);
        binding.btnIvLease.setOnClickListener(this::onClick);
        binding.btnIvPacker.setOnClickListener(this::onClick);
        binding.btnIvLogistics.setOnClickListener(this::onClick);
        binding.btnIvCorporateServices.setOnClickListener(this::onClick);
        binding.btnIvMember.setOnClickListener(this::onClick);
        binding.btnIvBusinessManagement.setOnClickListener(this::onClick);
        binding.btnIvMerchants.setOnClickListener(this::onClick);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.btn_iv_home) {
            listener.onItemClick(new QuickEntryEntity("网站推荐", "0"));
        } else if (id == R.id.btn_iv_commodity) {
            listener.onItemClick(new QuickEntryEntity("销售经营", "1"));
        } else if (id == R.id.btn_iv_bidding) {
            listener.onItemClick(new QuickEntryEntity("招标竞价", "2"));
        } else if (id == R.id.btn_iv_collect) {
            listener.onItemClick(new QuickEntryEntity("集采团购", "3"));
        } else if (id == R.id.btn_iv_lease) {
            listener.onItemClick(new QuickEntryEntity("租赁转让", "4"));
        } else if (id == R.id.btn_iv_packer) {
            listener.onItemClick(new QuickEntryEntity("工队工人", "5"));
        } else if (id == R.id.btn_iv_logistics) {
            listener.onItemClick(new QuickEntryEntity("物流货运", "6"));
        } else if (id == R.id.btn_iv_corporate_services) {
            listener.onItemClick(new QuickEntryEntity("企业服务", "7"));
        } else if (id == R.id.btn_iv_member) {
            listener.onItemClick(new QuickEntryEntity("会员经营", "8"));
        } else if (id == R.id.btn_iv_business_management) {
            listener.onItemClick(new QuickEntryEntity("企业经营", "9"));
        } else if (id == R.id.btn_iv_merchants) {
            listener.onItemClick(new QuickEntryEntity("招商引资", "10"));
        }
    }

    public void setListener(QuickEntryClickListener listener) {
        this.listener = listener;
        QuickEntryAdapter commodityAdapter = new QuickEntryAdapter(mContext, QuickEntryMenuManage.getCommodityMenu());
        commodityAdapter.setListener(listener);
        binding.recyclerCommodity.setAdapter(commodityAdapter);
        QuickEntryAdapter biddingAdapter = new QuickEntryAdapter(mContext, QuickEntryMenuManage.getBiddingMenu());
        biddingAdapter.setListener(listener);
        binding.recyclerBidding.setAdapter(biddingAdapter);
        QuickEntryAdapter collectAdapter = new QuickEntryAdapter(mContext, QuickEntryMenuManage.getCollectMenu());
        collectAdapter.setListener(listener);
        binding.recyclerCollect.setAdapter(collectAdapter);
        QuickEntryAdapter leaseAdapter = new QuickEntryAdapter(mContext, QuickEntryMenuManage.getLeaseMenu());
        leaseAdapter.setListener(listener);
        binding.recyclerLease.setAdapter(leaseAdapter);
        QuickEntryAdapter packerAdapter = new QuickEntryAdapter(mContext, QuickEntryMenuManage.getPackersMenu());
        packerAdapter.setListener(listener);
        binding.recyclerPacker.setAdapter(packerAdapter);
        QuickEntryAdapter logisticsAdapter = new QuickEntryAdapter(mContext, QuickEntryMenuManage.getLogisticsMenu());
        logisticsAdapter.setListener(listener);
        binding.recyclerLogistics.setAdapter(logisticsAdapter);
        QuickEntryAdapter corporateServicesAdapter = new QuickEntryAdapter(mContext, QuickEntryMenuManage.getCorporateServicesMenu());
        corporateServicesAdapter.setListener(listener);
        binding.recyclerCorporateServices.setAdapter(corporateServicesAdapter);
        QuickEntryAdapter memberAdapter = new QuickEntryAdapter(mContext, QuickEntryMenuManage.getMemberMenu());
        memberAdapter.setListener(listener);
        binding.recyclerMember.setAdapter(memberAdapter);
        QuickEntryAdapter businessManagementAdapter = new QuickEntryAdapter(mContext, QuickEntryMenuManage.getBusinessManagementMenu());
        businessManagementAdapter.setListener(listener);
        binding.recyclerBusinessManagement.setAdapter(businessManagementAdapter);
        QuickEntryAdapter merchantsAdapter = new QuickEntryAdapter(mContext, QuickEntryMenuManage.getMerchantsMenu());
        merchantsAdapter.setListener(listener);
        binding.recyclerMerchants.setAdapter(merchantsAdapter);
    }

    public void setRecover(){
        if (binding != null){
            binding.scrollView.scrollTo(0, 0);
        }
    }
}
